package com.pzsh.service.impl;

import com.pzsh.entity.AppVersionEntity;
import com.pzsh.mapper.AppVersionMapper;
import com.pzsh.service.IAPPService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description:
 * @Param:
 * @return:
 * @Author: GXL
 * @Date: 2019/12/16
 */
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class APPServiceImpl implements IAPPService {

    @Autowired
    private AppVersionMapper appVersionMapper;
    @Transactional(propagation=Propagation.REQUIRED)
    @Override
    public void insertApp(String appVersion, String appDiscreption, String appPath, Integer mustUpdate, Integer appType) {
        AppVersionEntity appVersionEntity = new AppVersionEntity();
        appVersionEntity.setAppDiscreption(appDiscreption);
        appVersionEntity.setAppVersion(appVersion);
        appVersionEntity.setAppPath(appPath);
        appVersionEntity.setMustUpdate(mustUpdate);
        appVersionEntity.setAppType(appType);
        appVersionMapper.insert(appVersionEntity);
    }
    @Transactional(propagation=Propagation.REQUIRED)
    @Override
    public List<AppVersionEntity> selectApp() {
        List<AppVersionEntity>  list = appVersionMapper.selectAll();
        return list;
    }
    @Transactional(propagation=Propagation.REQUIRED)
    @Override
    public AppVersionEntity getLastApp(Integer appType) {

        AppVersionEntity appVersionEntity = new AppVersionEntity();
        appVersionEntity.setAppType(appType);
        List<AppVersionEntity> list = appVersionMapper.select(appVersionEntity);
        AppVersionEntity a = list.get(0);
        for (AppVersionEntity app : list) {
            if (app.getId() > a.getId()){
                a = app;
            }
        }
        return a;
    }
}
